package com.eric.statemachinedemo.model.response;

import com.eric.statemachinedemo.constant.ResponseCodeEnum;
import com.eric.statemachinedemo.util.MessageSourceUtils;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.lang.Nullable;

public class ResponseResult {

    //操作是否成功
    boolean success = true;

    //操作代码
    int code = 200;

    //提示信息
    String message;

    public ResponseResult(ResponseCodeEnum responseCodeEnum, @Nullable Object... args){
        this.success = responseCodeEnum.success();
        this.code = responseCodeEnum.code();
        this.message = MessageSourceUtils.getMessage(String.valueOf(responseCodeEnum.code()), args, LocaleContextHolder.getLocale());
    }

    public ResponseResult(ResponseCodeEnum responseCodeEnum){
        this(responseCodeEnum, null);
    }

    public boolean isSuccess() {
        return success;
    }

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }
}
